#ifndef DOUBAN_MINIBLOG_MINIBLOGMODULE_P_H
#define DOUBAN_MINIBLOG_MINIBLOGMODULE_P_H

#include "douban_global.h"
#include "MiniBlogEntry.h"
#include "MiniBlogLayout.h"
#include "ReplyViewer.h"
#include <QNetworkAccessManager>
#include <QXmlStreamReader>
#include <QScrollBar>
#include <QPointer>
#include <QTimer>
#include <QList>

class QUrl;
class QScrollBar;
class QVBoxLayout;
class QNetworkReply;
struct MiniBlogEntryReplication;
namespace Douban
{
	class EventViewer;
	class DoubanContext;
	class MiniBlogModule;
	class RecommendViewer;
	class MiniBlogEntryWidget;

	class MiniBlogModulePrivate : public QObject
	{
		Q_OBJECT
		public:
			~MiniBlogModulePrivate();
			bool eventFilter(QObject *, QEvent *);
			static void NotifyCB(QObject* pt2object,const QString&);

		private:
			MiniBlogModulePrivate(MiniBlogModule*,DoubanContext*);

			MiniBlogModule*	m_pImpl;
			DoubanContext*	m_context;
			QTimer			m_updateTimer;

			int							i_maxEntryCount;
			QMap<DoubanId,MiniBlogEntry*> m_entries;
			QList<MiniBlogEntry*>		m_newEntries;
			QList<MiniBlogEntry*>		m_recycleEntries;
			QList<MiniBlogEntryWidget*> m_recycleWidgets;
			MiniBlogEntryReplication	m_miniBlogEntryHolder;

			int					i_scrollExceed;
			int					i_lastCheckUpdatedCount;
			bool				b_secondPageChecked;
			QNetworkReply*		m_checkMiniBlogReply;
			QXmlStreamReader		m_xmlParser;

			QWidget			m_miniblogWidget;
			QWidget			m_parentWidget;
			QScrollBar		m_scrollBar;
			MiniBlogLayout	m_layout;
			ReplyViewer		m_replyViewer;

			QPointer<RecommendViewer> m_recommendViewer;
			QPointer<EventViewer> m_eventViewer;

			QNetworkAccessManager m_imageDownloader;

			void setMaxEntryCount(int count);
			void parseMiniBlog();
			void notifyCallBack();

			MiniBlogEntry*			getEntry();
			MiniBlogEntryWidget*	getWidget();
			void deleteEntry(MiniBlogEntry*);
		private slots:
			void scrollMiniBlog(int);
			void checkMiniBlog();
			void checkMiniBlogFinished();

		private:
			static const QString API_MINIBLOG_URL;
			static const QString API_MINIBLOG_URL_ENCODED;
		friend class MiniBlogModule;
	};
}

#endif /* MINIBLOGMODULE_P_H_ */
